package com.antovita.militarymonkey.service;
import java.util.*;
import com.badlogic.gdx.*;
import com.badlogic.gdx.audio.*;

public class MusicBox {
	private static MusicBox mb;
	private Map<Action, Object> map;
	protected MusicBox() {
		map = new HashMap<Action, Object>();
		Music menu = Gdx.audio.newMusic(Gdx.files.internal("audio/menu.mp3"));
		menu.setLooping(true);
		map.put(Action.MENU, menu);
		Music game = Gdx.audio.newMusic(Gdx.files.internal("audio/game.mp3"));
		game.setLooping(true);
		map.put(Action.GAME, game);
		map.put(Action.SHOT, Gdx.audio.newSound(Gdx.files.internal("audio/shot.mp3")));
		map.put(Action.PAIN, Gdx.audio.newSound(Gdx.files.internal("audio/pain.mp3")));
		map.put(Action.BIRD, Gdx.audio.newSound(Gdx.files.internal("audio/bird.mp3")));
		map.put(Action.BANAN, Gdx.audio.newSound(Gdx.files.internal("audio/banan.mp3")));
		map.put(Action.COCO, Gdx.audio.newSound(Gdx.files.internal("audio/coco.mp3")));
		map.put(Action.EATING, Gdx.audio.newSound(Gdx.files.internal("audio/eating.mp3")));
	}
	public static MusicBox getInstance() {
		if (mb == null)
			mb = new MusicBox();
		return mb;
	}
	public void play(Action act) {
		Object obj = map.get(act);
		if (obj instanceof Sound)
			((Sound)obj).play();
		else 
			((Music)obj).play();
	}
	public void pause(Action act) {
		Object obj = map.get(act);
		if (obj instanceof Sound)
			((Sound)obj).pause();
		else 
			((Music)obj).pause();
	}
	public void stop(Action act) {
		Object obj = map.get(act);
		if (obj instanceof Sound)
			((Sound)obj).stop();
		else 
			((Music)obj).stop();
	}
	public void stopMusic() {
		Collection<Object> col = map.values();
		for (Object obj: col)
			if (obj instanceof Music)
				((Music)obj).stop();
	}
	public void dispose() {
		Collection<Object> col = map.values();
		for (Object obj: col)
			if (obj instanceof Sound)
				((Sound)obj).dispose();
			else 
				((Music)obj).dispose();
		map.clear();
	}
}

